Component({
  /**
   * 页面的初始数据
   */
  data: {
    url: ''
  },
  properties: {
    domain: {
      type: String,
      value: ''
    }
  },
  lifetimes: {
    attached() {
      this.init()
    }
  },
  observers: {
    domain() {
      this.init()
    }
  },
  methods: {
    init() {
      const _this = this
      if (_this.properties.domain) {
        wx.login({
          success(res) {
            if (res.code) {
              let connect = '?'
              if (_this.properties.domain.indexOf('?') > 0) {
                connect = '&'
              }
              // 发起网络请求
              _this.setData({
                url: _this.properties.domain + connect + 'miniCode=' + res.code
              })
            } else {
              // eslint-disable-next-line no-console
              console.log('登录失败！', res.errMsg)
            }
          }
        })
      }
    },
    getUrlByMiniId() {
      // const accountInfo = wx.getAccountInfoSync()
    }
  }
})
